/**   
* @Description: Swagger 集成测试 
*/ 
package org.kskj.ipw.controller.swagger;

import java.util.HashMap;
import java.util.Map;

import org.kskj.ipw.controller.BaseController;
import org.kskj.ipw.entity.ResponseEntity;
import org.kskj.ipw.validator.annotation.IsDigit;
import org.kskj.ipw.validator.annotation.ParamValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/** 
* @author sztan 
* @date 2016年8月2日 上午11:28:43 
* @version 1.0 
*/
@Api(value="/swagger/test", description="swagger测试", produces=MediaType.APPLICATION_JSON_VALUE)
@Controller
@RequestMapping(value="/swagger/test")
public class SwaggerTestController extends BaseController{
	private static final Logger LOGGER = LoggerFactory.getLogger(SwaggerTestController.class);
	
	@RequestMapping(value="/name", method={RequestMethod.POST})
	@ResponseBody
	@ApiOperation(value = "根据用户名获取用户对象", httpMethod = "POST", response = ResponseEntity.class, notes = "根据用户名获取用户对象")
	@ParamValidator
	public ResponseEntity getUserInfo(
			@ApiParam(required=true, name="age", value="年龄")
			@RequestParam @IsDigit(handle="org.kskj.ipw.validator.handle.customized.IsDigitValidatorCustomizedHandle", message="AAAAAAAAAAA") String age, 
			@ApiParam(required=true, name="name", value="姓名")
			@RequestParam String name) {
		try {
			Map <String, Object> result = new HashMap<String, Object>();
			if ("A".equals(name)) {
				result.put("name", "AAAA");
			} else {
				result.put("name", "BBBB");
			}
			return success(result);
		} catch (Exception ex) {
			LOGGER.error("getUserInfo name={} age={}, 异常=", name, age, ex);
			return error(ex.getMessage());
		}
	}
}
